package com.bawei.liuzhanlin20210806.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bawei.liuzhanlin20210806.presenter.BasePresenter;
import com.bawei.liuzhanlin20210806.view.interfaces.BaseView;

/**
 * Time: 2021/8/6
 * Author:liuzhanlin
 * Description:zhuangao6
 */
public abstract class BaseFragment<P extends BasePresenter> extends Fragment implements BaseView {
    private P presenter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getlayout(), container, false);
        initview(view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        presenter = initpresenter();
        presenter.acesView(this);
        initdata();

    }

    public P getPresenter() {
        return presenter;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (presenter != null){
            presenter.caseView();
        }
    }

    public abstract int getlayout();
    public abstract void initview(View v);
    public abstract P initpresenter();
    public abstract void initdata();
}
